package com.mdd.admin.controller.client;

import com.mdd.admin.aop.Log;
import com.mdd.admin.service.IClientCrmProjetDetailService;
import com.mdd.admin.validate.commons.IdValidate;
import com.mdd.admin.validate.ClientCrmProjetDetailCreateValidate;
import com.mdd.admin.validate.ClientCrmProjetDetailUpdateValidate;
import com.mdd.admin.validate.ClientCrmProjetDetailSearchValidate;
import com.mdd.admin.validate.commons.PageValidate;
import com.mdd.admin.vo.ClientCrmProjetDetailListedVo;
import com.mdd.admin.vo.ClientCrmProjetDetailDetailVo;
import com.mdd.common.core.AjaxResult;
import com.mdd.common.core.PageResult;
import com.mdd.common.entity.CustomerMian;
import com.mdd.common.validator.annotation.IDMust;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("api/detail")
@Api(tags = "项目基本信息管理")
public class ClientCrmProjetDetailController {

    @Resource
    IClientCrmProjetDetailService iClientCrmProjetDetailService;

    @GetMapping("/list")
    @ApiOperation(value="项目基本信息列表")
    public AjaxResult<PageResult<ClientCrmProjetDetailListedVo>> list(@Validated PageValidate pageValidate,
                                                     @Validated ClientCrmProjetDetailSearchValidate searchValidate) {
        PageResult<ClientCrmProjetDetailListedVo> list = iClientCrmProjetDetailService.list(pageValidate, searchValidate);
        return AjaxResult.success(list);
    }

    @GetMapping("/detail")
    @ApiOperation(value="项目基本信息详情")
    public AjaxResult<ClientCrmProjetDetailDetailVo> detail(@Validated @IDMust() @RequestParam("id") Integer id) {
        ClientCrmProjetDetailDetailVo detail = iClientCrmProjetDetailService.detail(id);
        return AjaxResult.success(detail);
    }

    @Log(title = "项目基本信息新增")
    @PostMapping("/add")
    @ApiOperation(value="项目基本信息新增")
    public AjaxResult<Object> add(@Validated @RequestBody ClientCrmProjetDetailCreateValidate createValidate) {
        iClientCrmProjetDetailService.add(createValidate);
        return AjaxResult.success();
    }

    @Log(title = "项目基本信息编辑")
    @PostMapping("/edit")
    @ApiOperation(value="项目基本信息编辑")
    public AjaxResult<Object> edit(@Validated @RequestBody ClientCrmProjetDetailUpdateValidate updateValidate) {
        iClientCrmProjetDetailService.edit(updateValidate);
        return AjaxResult.success();
    }

    @Log(title = "项目基本信息删除")
    @PostMapping("/del")
    @ApiOperation(value="项目基本信息删除")
    public AjaxResult<Object> del(@Validated @RequestBody IdValidate idValidate) {
        iClientCrmProjetDetailService.del(idValidate.getId());
        return AjaxResult.success();
    }

    @Log(title = "项目政策信息匹配公司")
    @PostMapping("/matching")
    @ApiOperation(value="项目基本信息匹配公司")
    public AjaxResult< List<CustomerMian>> matching(@Validated @RequestBody ClientCrmProjetDetailSearchValidate searchValidate) {
        return  AjaxResult.success(iClientCrmProjetDetailService.matching(searchValidate));
    }
}
